# source-code\my_ignore.py

from gitignore_parser import parse_gitignore
from pathlib import Path

def get_ignore(path : Path, other_ignore = None):
    """
    获取指定路径下的忽略规则

    Args:
        path (Path): 目标路径
        other_ignore (list, optional): 其他忽略规则. Defaults to None.

    Returns:
        list: 包含忽略规则集的列表
    """

    # ---------
    # 用于以后更新other_ignore
    # ---------

    # 健壮性处理
    if type(path) != Path:
        try:
            path = Path(path)
        except:
            raise TypeError('path must be a Path object or a right string')

    # 获取忽略规则
    ignore_patn = path / '.gitignore'

    try:
        matches = parse_gitignore(ignore_patn)
        return matches
    except:
        return None

    
    

def is_ignore(ignore , path: Path):
    """
    判断指定路径是否被忽略

    Args:
        ignore (list): get_ignore()函数的返回值、parse_gitignore(ignore_patn)的返回值
        path (Path): 目标路径

    Returns:
        bool: 是否被忽略
    """
    if type(path) != Path:
        try:
            path = Path(path)
        except:
            raise TypeError('path must be a Path object or a right string')
        
    return ignore(path)

    
    

    
